---
title:        'K-factor Calibration Pattern'
description:  'Create Gcode to calibrate LIN_ADVANCE setting'
category:     [ tools ]
---
<script language="JavaScript" type="text/javascript" src="/assets/javascript/jquery-2.2.1.min.js"></script>
<script language="JavaScript" type="text/javascript" src="/assets/javascript/jquery-ui.min.js"></script>
<script language="JavaScript" type="text/javascript" src="./FileSaver.min.js"></script>
<script language="JavaScript" type="text/javascript" src="./k-factor.js"></script>
<div class="container" role="main">
  <div class="row">
    <div class="calibpat" id="calibpat">
      <h1>K-factor Calibration Pattern</h1>
      <p>The below Javascript will generate G-Code that will support the user in calibrating the K-factor for Marlin's Linear Advance Feature. The default values should work for a standard PLA material with a 0.4 mm nozzle.      </p>
      <p>Press the <code class="highlighter-rouge">Generate G-code</code> button then  <code class="highlighter-rouge">Download as file</code> to save the result.</p>
      <table>
        <tbody>
          <tr>
            <td colspan="3" class="tdHead"><h3>Settings</h3></td>
            <td class="tdHead"><h3>G-code</h3></td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Printer:</h4></td>
            <td rowspan="34" class="txtareatd"><textarea name="textarea" id="textarea"></textarea></td>
          </tr>
          <tr>
            <td><label for="FIL_DIA">Filament Diameter:</label></td>
            <td><input name="FIL_DIA" type="number" id="FIL_DIA" step="any" tabindex="1" value="1.75"></td>
            <td>Diameter of the used filament (mm)</td>
          </tr>
          <tr>
            <td><label for="NOZ_DIA">Nozzle Diameter:</label></td>
            <td><input name="NOZ_DIA" type="number" id="NOZ_DIA" step="any" tabindex="2" value="0.4"></td>
            <td>Diameter of the nozzle (mm)</td>
          </tr>
          <tr>
            <td><label for="NOZZLE_TEMP">Nozzle Temperature:</label></td>
            <td><input name="NOZZLE_TEMP" type="number" id="NOZZLE_TEMP" step="any" tabindex="3" value="205"></td>
            <td>Nozzle Temperature (°C)</td>
          </tr>
          <tr>
            <td><label for="BED_TEMP">Bed Temperature:</label></td>
            <td><input name="BED_TEMP" type="number" id="BED_TEMP" step="any" tabindex="4" value="60"></td>
            <td>Bed Temperature (°C)</td>
          </tr>
          <tr>
            <td><label for="RETRACTION">Retraction Distance:</label></td>
            <td><input name="RETRACTION" type="number" id="RETRACTION" step="any" tabindex="5" value="1"></td>
            <td>Retraction distance (mm)</td>
          </tr>
          <tr>
            <td><label for="LAYER_HEIGHT">Layer Height:</label></td>
            <td><input name="LAYER_HEIGHT" type="number" id="LAYER_HEIGHT" step="0.1" tabindex="6" value="0.2"></td>
            <td>Layer Height (mm)</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Print Bed:</h4></td>
          </tr>
          <tr>
            <td><label for="BEDSIZE_X">Bed Size X:</label></td>
            <td><input name="BEDSIZE_X" type="number" id="BEDSIZE_X" step="any" tabindex="8" value="200"></td>
            <td>Size (mm) of the bed in X</td>
          </tr>
          <tr>
            <td><label for="BEDSIZE_Y">Bed Size Y:</label></td>
            <td><input name="BEDSIZE_Y" type="number" id="BEDSIZE_Y" step="any" tabindex="9" value="200"></td>
            <td>Size (mm) of the bed in Y</td>
          </tr>
          <tr>
            <td><label for="CENTER_NULL">Origin Bed Center:</label></td>
            <td><input name="CENTER_NULL" type="checkbox" id="CENTER_NULL" tabindex="10"></td>
            <td>Use to move the origin position (x 0, y 0) to bed center instead of front left corner</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Speed:</h4></td>
          </tr>
          <tr>
            <td><label for="MM_S">Use mm/s: </label></td>
            <td><input name="MM_S" type="checkbox" id="MM_S" tabindex="11" checked></td>
            <td>Use mm/s instead of mm/min</td>
          </tr>
          <tr>
            <td><label for="SLOW_SPEED">Slow Printing Speed:</label></td>
            <td><input name="SLOW_SPEED" type="number" id="SLOW_SPEED" step="any" tabindex="12" value="20"></td>
            <td>Slow printing speed</td>
          </tr>
          <tr>
            <td><label for="FAST_SPEED">Fast Printing Speed:</label></td>
            <td><input name="FAST_SPEED" type="number" id="FAST_SPEED" step="any" tabindex="13" value="70"></td>
            <td>Fast printing speed. This should differ noticeably from Slow Speed.</td>
          </tr>
          <tr>
            <td><label for="MOVE_SPEED">Movement Speed:</label></td>
            <td><input name="MOVE_SPEED" type="number" id="MOVE_SPEED" step="any" tabindex="14" value="120"></td>
            <td>Movement speed</td>
          </tr>
          <tr>
            <td><label for="PRINT_ACCL">Acceleration:</label></td>
            <td><input name="PRINT_ACCL" type="number" id="PRINT_ACCL" step="any" tabindex="15" value="500"></td>
            <td>Set printing acceleration (mm/s^2)</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>K-factor:</h4></td>
          </tr>
          <tr>
            <td><label for="K_START">Starting Value for K:</label></td>
            <td><input name="K_START" type="number" id="K_START" step="1" tabindex="16" value="0"></td>
            <td>Starting value for the K-factor. Usually 0 but for bowden setups you might want to start higher, e.g. 30</td>
          </tr>
          <tr>
            <td><label for="K_END">Ending Value for K:</label></td>
            <td><input name="K_END" type="number" id="K_END" step="1" tabindex="17" value="100"></td>
            <td>Ending value of the K-factor. Bowden setups may be higher than 100</td>
          </tr>
          <tr>
            <td><label for="K_STEP">K-factor Stepping:</label></td>
            <td><input name="K_STEP" type="number" id="K_STEP" step="1" tabindex="18" value="5"></td>
            <td>Stepping of the K-factor in the test pattern. Needs to be an exact divisor of the K-factor Range (End - Start)</td>
          </tr>
          <tr>
            <td><label for="SLOW_LENGTH">Slow Speed Length:</label></td>
            <td><input name="SLOW_LENGTH" type="number" id="SLOW_LENGTH" step="1" tabindex="19" value="20"></td>
            <td>Length of the Slow Speed test-line (mm)</td>
          </tr>
          <tr>
            <td><label for="FAST_LENGTH">Fast Speed Length:</label></td>
            <td><input name="FAST_LENGTH" type="number" id="FAST_LENGTH" step="1" tabindex="20" value="40"></td>
            <td>Length of the Fast Speed test-line (mm)</td>
          </tr>
          <tr>
            <td><label for="PAT_ALT">Alternate Pattern:</label></td>
            <td><input name="PAT_ALT" type="checkbox" id="PAT_ALT" tabindex="21"></td>
            <td>Switches to an alternate calibration pattern. Anchor frame is not compatible with this type</td>
          </tr>
          <tr>
            <td colspan="3" class="tdSection"><h4>Advanced:</h4></td>
          </tr>
          <tr>
            <td><label for="NOZ_LIN_R">Nozzle Line Ratio:</label></td>
            <td><input name="NOZ_LIN_R" type="number" id="NOZ_LIN_R" step="0.1" tabindex="22" value="1.2"></td>
            <td>Ratio between nozzle diameter and extruded line width. Should be between 1.05 and 1.2</td>
          </tr>
          <tr>
            <td><label for="USE_BL">Use Bed Leveling:</label></td>
            <td><input name="USE_BL" type="checkbox" id="USE_BL" tabindex="23"></td>
            <td>Level bed before printing. Bed leveling has to be activated</td>
          </tr>
          <tr>
            <td><label for="EXTRUSION_MULT">Extrusion Multiplier:</label></td>
            <td><input name="EXTRUSION_MULT" type="number" id="EXTRUSION_MULT" step="0.1" tabindex="24" value="1.0"></td>
            <td>Usually 1.0</td>
          </tr>
          <tr>
            <td><label for="DIR_PRINT">Printing Direction:</label></td>
            <td><select name="DIR_PRINT" id="DIR_PRINT" tabindex="25">
                <option value="0" selected>Left to Right (0°)</option>
                <option value="45">45°</option>
                <option value="90">Front to Back (90°)</option>
                <option value="135">135°</option>
                <option value="180">Right to Left (180°)</option>
                <option value="225">225°</option>
                <option value="270">Back to Front (270°)</option>
                <option value="315">315°</option>
              </select></td>
            <td>Rotates the print in 45° steps</td>
          </tr>
          <tr>
            <td><label for="FRAME">Print Anchor Frame:</label></td>
            <td><input name="FRAME" type="checkbox" id="FRAME" tabindex="26"></td>
            <td>Adds a frame around the start and end points of the test lines. May improve adhesion</td>
          </tr>
          <tr>
            <td><label for="SPACE_LINE">Test Line Spacing:</label></td>
            <td><input name="SPACE_LINE" type="number" id="SPACE_LINE" step="0.1" tabindex="27" value="5"></td>
            <td>Distance between the test lines. This will impact print size</td>
          </tr>
          <tr>
            <td><label for="PRIME">Prime Nozzle:</label></td>
            <td><input name="PRIME" type="checkbox" id="PRIME" tabindex="28" checked></td>
            <td>Prime the nozzle before starting the test pattern</td>
          </tr>
          <tr>
            <td><label for="PRIME_EXT">Prime Extrusion Multiplier:</label></td>
            <td><input name="PRIME_EXT" type="number" id="PRIME_EXT" step="0.1" tabindex="29" value="2.5"></td>
            <td>The default of 2.5 results in roughly 1mm of filament for 10mm line length</td>
          </tr>
          <tr>
            <td><label for="DWELL_PRIME">Prime Dwell:</label></td>
            <td><input name="DWELL_PRIME" type="number" id="DWELL_PRIME" step="0.1" tabindex="30" value="2"></td>
            <td>Inserts a pause of x seconds before starting the test pattern to bleed off any residual nozzle pressure</td>
          </tr>
          <tr class="calibpat2">
            <td colspan="3"><p>
                <input name="button" type="button" id="button" tabindex="31" onclick="genGcode()" value="Generate G-code">
              </p></td>
            <td><p>
                <input name="button2" type="button" id="button2" tabindex="32" onclick="saveTextAsFile()" value="Download as file">
              </p></td>
          </tr>
        </tbody>
      </table>
      <h3>Notes on the settings:</h3>
      <ul>
        <li><code class="highlighter-rouge">Fast Printing Speed</code> and <code class="highlighter-rouge">Slow Printing Speed</code> should be significantly different or the K-factor effect will barely be visible.</li>
        <li><code class="highlighter-rouge">Use Bed Leveling</code> requires a probe.</li>
        <li>The print-bed is assumed to be rectangular because <code class="highlighter-rouge">LIN_ADVANCE</code> is only compatible with Cartesian machines.</li>
        <li>The overall width (X-direction) of the print depends on the <code class="highlighter-rouge">Fast Speed Length</code> and <code class="highlighter-rouge">Slow Speed Length</code> settings plus 10 mm for the priming line. The length (Y-direction) depends on the K-factor Settings and <code class="highlighter-rouge">Line Spacing</code>.</li>
        <li>The script performs sanity checks if the print fits on the bed. Verify it using a host software like <a href="http://www.pronterface.com/" target="new">Printrun</a> or <a href="https://www.repetier.com/" target="new">Repetier Host</a>.</li>
        <li><code class="highlighter-rouge">Start</code> and <code class="highlighter-rouge">End Value</code> for the K-factor determines the range that the test pattern will cover. For example a <code class="highlighter-rouge">Start Value</code> of 50 and an <code class="highlighter-rouge">End Value</code> of 150 will test a range of 100.</li>
        <li>The <code class="highlighter-rouge">K-factor Stepping</code> determines how many test lines are printed for the above range. For example, a Stepping of 10 and a range of 100 results in 10 test lines. A stepping of 3 would not work in this example as 100 cannot be exactly divided by 3. The script will throw an error message if an exact division is not possible. In this case either the range or the  stepping needs to be adjusted.</li>
        <li>The <code class="highlighter-rouge">Alternate Pattern</code> has a second line of <code class="highlighter-rouge">Fast Printing Speed</code> to test 0 to <code class="highlighter-rouge">Fast Printing Speed</code> and back to 0 conditions. Best used with an increased <code class="highlighter-rouge">Test Line Spacing</code> and reduced K-factor range.</li>
        <li>The proper K-factor depends on the filament, nozzle size, nozzle geometry and printing temperature. If any of these values change, the calibration might need to be repeated.</li>
      </ul>
      <h2>Screen-shots</h2>
      <p>The following screen-shots show some examples of the test patterns</p>
      <ul>
        <li>Blue Lines are Slow Printing Speeds</li>
        <li>Red Lines are Fast Printing Speed</li>
        <li>Light blue lines are movements</li>
      </ul>
      <h3>Standard Pattern</h3>
      <p><img src="/assets/images/features/lin_advance/std_pattern.png" alt="StandardPattern"></p>
      <br>
      <h3>Alternate Pattern with increased Test Line Spacing</h3>
      <p><img src="/assets/images/features/lin_advance/alt_pattern.png" alt="AlternatePattern"></p>
      <br>
      <h3>Standard Pattern with Frame</h3>
      <p><img src="/assets/images/features/lin_advance/frame_pattern.png" alt="FramePattern"></p>
      <br>
      <h3>45° rotated Alternate Pattern</h3>
      <p><img src="/assets/images/features/lin_advance/rot_pattern.png" alt="RotatedPattern"></p>
    </div>
  </div>
</div>
